<template>
  <el-row :gutter="6">
    <!-- <myAnnounceDlg @operationSucc="operationState($event)" :configs="myAnnounceDlgConfig"></myAnnounceDlg> -->
    <el-col :span="24" class="col-flex">
      <el-col class="breadcrumb-container">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/quality' }">质量控制</el-breadcrumb-item>
          <el-breadcrumb-item>勘察纲要</el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
      <el-col class="maincont-container">
        <div id="tableview" v-if="config.tableshow">
          <el-tabs v-model="tabConfig.activeName">
            <el-tab-pane label="我的待办" name="first">
              <my-tableX
                v-if="tabConfig.activeName==='first'"
                element-loading-text="正在删除......"
                element-loading-spinner="el-icon-loading"
                @dataEdit="handleData"
                @dataAdd="addNewBusiness"
                :tableData="mytaskdata"
                :configs="configsmytask"
              ></my-tableX>
            </el-tab-pane>
            <el-tab-pane label="运行记录" name="second">
              <my-tableX
                v-if="tabConfig.activeName==='second'"
                @dataView="viewData"
                :tableData="processingdata"
                :configs="configsprocessing"
              ></my-tableX>
            </el-tab-pane>
            <el-tab-pane label="历史记录" name="third">
              <my-tableX
                v-if="tabConfig.activeName==='third'"
                @dataView="viewData"
                :tableData="finisheddata"
                :configs="configsfinished"
              ></my-tableX>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div class="flow-container" v-if="!config.tableshow" style="overflow:hidden; ">
          <div class="step">
            <my-stepX :configs="stepconfigs"></my-stepX>
          </div>
          <div
            class="flow-form"
            v-loading="config.loading"
            element-loading-text="正在提交......"
            element-loading-spinner="el-icon-loading"
          >
            <el-form
              size="small"
              :model="ruleForm"
              :rules="currentRule"
              ref="ruleForm"
              label-width="0px"
              height="100%"
            >
              <h4 class="form-title" v-html="businessConfig.formTitle"></h4>
              <table border="1px" cellpadding="0" cellspaceing="0" class="form-data">
                <tr align="center">
                  <td class="form-label" colspan="1" width="10%">编号</td>
                  <td colspan="2" width="20%">
                    <el-input
                      placeholder="自动生成"
                      size="small"
                      :readonly="true"
                      v-model="ruleForm.outline_id"
                    ></el-input>
                  </td>
                  <td class="form-label" colspan="3" width="30%">勘察标段/勘察单位</td>
                  <td colspan="4" width="40%">
                    <el-input size="small" :readonly="true" v-model="ruleForm.tenders"></el-input>
                  </td>
                </tr>

                <tr align="center">
                  <td class="form-label" colspan="1" width="10%">工程编号</td>
                  <td colspan="2" width="20%">
                    <el-form-item :show-message="false" prop="project_id">
                      <el-select
                        placeholder="请选择工程编号"
                        v-model="ruleForm.project_id"
                        @change="changeProjectId"
                        :disabled="flowConfig.step!==0"
                      >
                        <el-option
                          v-for="item in projectData"
                          :key="item.projectId"
                          :label="item.projectId"
                          :value="item.projectId"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">工程名称</td>
                  <td colspan="6" width="60%">
                    <el-form-item :show-message="false" prop="project_name">
                      <el-select
                        v-model="ruleForm.project_name"
                        :disabled="flowConfig.step!==0"
                        placeholder="请选择工程名称"
                        @change="changeProjectName"
                      >
                        <el-option
                          :label="item.projectName"
                          :value="item.projectName"
                          v-for="item in this.projectData"
                          :key="item.projectId"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </td>
                </tr>
                <!-- 时间计划行 均分10份 -->
                <tr align="center">
                  <td class="form-label" colspan="1" width="10%">策划完成</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="plan">
                      <el-date-picker
                        :readonly="flowConfig.step!==0"
                        prefix-icon="null"
                        v-model="ruleForm.plan"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :picker-options="planpickerOptions"
                        @change="changeplanpicker"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">外业完成</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="field_work">
                      <el-date-picker
                        prefix-icon="null"
                        :readonly="flowConfig.step!==0"
                        v-model="ruleForm.field_work"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :picker-options="fieldworkpickerOptions"
                        @change="changefieldworkpicker"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">内业完成</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="inside_work">
                      <el-date-picker
                        prefix-icon="null"
                        :readonly="flowConfig.step!==0"
                        v-model="ruleForm.inside_work"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :picker-options="insideworkpickerOptions"
                        @change="changeinsideworkpicker"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">总体校审</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="prospecting_verification">
                      <el-date-picker
                        prefix-icon="null"
                        :readonly="flowConfig.step!==0"
                        v-model="ruleForm.prospecting_verification"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :picker-options="pvpickerOptions"
                        @change="changepvpicker"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">成果提交</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="consultation_verification">
                      <el-date-picker
                        prefix-icon="null"
                        :readonly="flowConfig.step!==0"
                        v-model="ruleForm.consultation_verification"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :picker-options="cvpickerOptions"
                        @change="changecvpicker"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                </tr>
                <!-- 工作量行 均分4份 -->
                <tr align="center">
                  <td class="form-label" colspan="1" width="10%">钻孔数(个)</td>
                  <td class="form-label" colspan="2" width="20%">
                    <el-form-item prop="drilling_number">
                      <el-input v-model="ruleForm.drilling_number" :readonly="flowConfig.step!==0"></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">进尺(米)</td>
                  <td class="form-label" colspan="2" width="20%">
                    <el-form-item prop="length">
                      <el-input v-model="ruleForm.length" :readonly="flowConfig.step!==0"></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">监测井(个)</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="monitor_well">
                      <el-input
                        :readonly="flowConfig.step!==0"
                        :disabled="!majorRight"
                        v-model="ruleForm.monitor_well"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" colspan="1" width="10%">试验井(个)</td>
                  <td class="form-label" colspan="1" width="10%">
                    <el-form-item prop="test_well">
                      <el-input
                        :readonly="flowConfig.step!==0"
                        :disabled="!majorRight"
                        v-model="ruleForm.test_well"
                      ></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <!-- 附件行 -->
                <tr align="center" style="height:35px;padding-bottom:10px;">
                  <td class="form-label" width="10%">附件列表</td>
                  <td
                    :width="flowConfig.step===0?'90%':'90%'"
                    :colspan="flowConfig.step===0?9:9"
                    style="text-align:left"
                  >
                    <el-upload
                      v-if="fileList.length>0||flowConfig.step===0"
                      :disabled="flowConfig.step!==0"
                      ref="upload"
                      action="1"
                      :file-list="fileList"
                      :limit="5"
                      :accept="filetype"
                      :on-preview="handlePreview"
                      :on-remove="handleRemove"
                      :before-upload="beforeUpload"
                      :auto-upload="true"
                      :http-request="uploadSectionFile"
                      multiple
                    >
                      <el-button
                        v-if="flowConfig.step===0"
                        slot="trigger"
                        size="mini"
                        type="info"
                      >选取文件</el-button>
                      <div
                        v-if="flowConfig.step===0"
                        slot="tip"
                        class="el-upload__tip"
                      >上传图片、文档文件，每个不超过350M，最多上传5个，请上传完后再点击提交</div>
                    </el-upload>
                    <span v-if="fileList.length===0&&flowConfig.step>0">无</span>
                  </td>
                  <!-- <td width="10%" v-if="flowConfig.step===0">
                    <el-button size="mini" @click="submitUpload">上传</el-button>
                  </td>-->
                </tr>
                <!-- 流程审批意见 -->
                <tr align="center">
                  <td class="form-label" width="10%" colspan="1">总体审核人</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="firstApprover">
                      <el-input
                        size="small"
                        v-model="ruleForm.firstApprover"
                        :readonly="flowConfig.step!==1||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">联系方式</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="firstContact">
                      <el-input
                        size="small"
                        v-model="ruleForm.firstContact"
                        :readonly="flowConfig.step!==1||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">审核时间</td>
                  <td width="10%" colspan="1">
                    <el-input size="small" v-model="ruleForm.firstTime" readonly></el-input>
                  </td>
                  <td class="form-label" width="10%" colspan="1">回复人</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="firstAnswerApprover">
                      <el-input
                        size="small"
                        v-model="ruleForm.firstAnswerApprover"
                        :readonly="!(!flowConfig.isfirsttime&&flowConfig.step===0)||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">回复时间</td>
                  <td width="10%" colspan="1">
                    <el-input size="small" v-model="ruleForm.firstAnswerTime" readonly></el-input>
                  </td>
                </tr>
                <tr align="center">
                  <td class="form-label" width="10%" colspan="1">咨询审核人</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="secondApprover">
                      <el-input
                        size="small"
                        v-model="ruleForm.secondApprover"
                        :readonly="flowConfig.step!==2||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">联系方式</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="secondContact">
                      <el-input
                        v-model="ruleForm.secondContact"
                        size="small"
                        :readonly="flowConfig.step!==2||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">审核时间</td>
                  <td width="10%" colspan="1">
                    <el-input size="small" v-model="ruleForm.secondTime" readonly></el-input>
                  </td>
                  <td class="form-label" width="10%" colspan="1">回复人</td>
                  <td width="10%" colspan="1">
                    <el-form-item :show-message="false" prop="secondAnswerApprover">
                      <el-input
                        size="small"
                        v-model="ruleForm.secondAnswerApprover"
                        :readonly="!(!flowConfig.isfirsttime&&flowConfig.step===0)||config.onlyview"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td class="form-label" width="10%" colspan="1">回复时间</td>
                  <td width="10%" colspan="1">
                    <el-form-item>
                      <el-input v-model="ruleForm.secondAnswerTime" size="small" readonly></el-input>
                    </el-form-item>
                  </td>
                </tr>

                <tr class="form-label" align="center" style="height:36px">
                  <td colspan="6">审核意见</td>
                  <td colspan="4">意见回复</td>
                </tr>
                <tr align="center">
                  <td width="10%">勘察总体</td>
                  <td colspan="5" width="50%">
                    <el-form-item :show-message="false" prop="firstMessage">
                      <el-input
                        v-model="ruleForm.firstMessage"
                        type="textarea"
                        :rows="10"
                        :readonly="config.onlyview||flowConfig.step!==1"
                        placeholder="请输入审核意见"
                        resize="none"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td colspan="4" width="40%">
                    <el-form-item :show-message="false" prop="firstAnswerMessage">
                      <el-input
                        v-model="ruleForm.firstAnswerMessage"
                        :readonly="!(!flowConfig.isfirsttime&&flowConfig.step===0)||config.onlyview"
                        type="textarea"
                        :rows="10"
                        placeholder="请输入回复"
                        resize="none"
                      ></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr align="center">
                  <td width="10%">咨询单位</td>
                  <td colspan="5" width="50%">
                    <el-form-item :show-message="false" prop="secondMessage">
                      <el-input
                        v-model="ruleForm.secondMessage"
                        :readonly="config.onlyview||flowConfig.step!==2"
                        type="textarea"
                        :rows="10"
                        placeholder="请输入审核意见"
                        resize="none"
                      ></el-input>
                    </el-form-item>
                  </td>
                  <td colspan="4" width="40%">
                    <el-form-item :show-message="false" prop="secondAnswerMessage">
                      <el-input
                        v-model="ruleForm.secondAnswerMessage"
                        :readonly="!(!flowConfig.isfirsttime&&flowConfig.step===0)||config.onlyview"
                        type="textarea"
                        :rows="10"
                        placeholder="请输入回复"
                        resize="none"
                      ></el-input>
                    </el-form-item>
                  </td>
                </tr>
              </table>
              <!-- 操作按钮 -->
              <el-form-item class="btns">
                <el-button
                  type="primary"
                  @click="resolveFlow"
                  v-if="!config.onlyview"
                >{{btns.resolveText}}</el-button>
                <el-button
                  type="danger"
                  @click="rejectFlow"
                  v-if="!config.onlyview"
                >{{btns.rejectText}}</el-button>
                <el-button @click="cancelFlow()">{{btns.cancelText}}</el-button>
              </el-form-item>
            </el-form>
            <el-collapse>
              <el-collapse-item title="处理意见区" name="comment">
                <el-timeline style="text-align:left" :reverse="true">
                  <el-timeline-item v-for="(activity, index) in flowComments" :key="index">
                    <el-card>
                      <h4>审批意见</h4>
                      <p>{{activity.time+' '+activity.group_name+'-'+activity.approver+' '+'联系方式：'+activity.contact}}</p>
                      <h5>{{activity.message}}</h5>
                      <div v-if="activity.children.length>0">
                        <h4>回复</h4>
                        <p>{{activity.children[0].time+' '+activity.children[0].group_name+'-'+activity.children[0].approver}}</p>
                        <h5>{{activity.children[0].message}}</h5>
                      </div>
                    </el-card>
                  </el-timeline-item>
                </el-timeline>
              </el-collapse-item>
            </el-collapse>
          </div>
          <myExportTableBtn :configs="exportTableConfig"></myExportTableBtn>
        </div>
      </el-col>
    </el-col>
  </el-row>
</template>

<script>
import myTableX from "../../../components/base/tableX";
import myStepX from "../../../components/base/stepX";
// import myAnnounceDlg from "@/components/base/announceDlg";
import { formatDate } from "@/utils/date";
import { random } from "@/utils/random";
import httpfile from "@/api/file/index";
import FILE_TYPE from "@/config/file.type.config";
import { confirm } from "@/utils/confirm";
import myExportTableBtn from "@/components/base/exportTableBtn";
// 全局变量们
var glbUserRoleId;
var glbUserId;
var glbUser;
var glbSubjectId;

var listParam = {};

var refRoles = [];

export default {
  components: { myTableX, myStepX, myExportTableBtn },
  inject: ["reload"],
  data() {
    var glbColumns = [
      { field: "outline_id", name: "编号", canSort: true },
      { field: "tenders", name: "勘察标段/勘察单位" },
      { field: "project_id", name: "工程编号" },
      { field: "project_name", name: "工程名称" },
    ];
    return {
      //上传是否完成，完成后才可提交
      isUploadFinished: false,
      fileListLength: 0,

      progressInfo: {},

      config: {
        tableshow: true,
        onlyview: false,
        loading: false,
      },

      tabConfig: {
        activeName: "first",
      },

      projectData: [],

      // 步骤条配置信息
      stepconfigs: {
        active: 0,
        processstatus: "process",
        data: [
          { flow_node_name: "勘察单位提交勘察纲要审批" },
          { flow_node_name: "勘察总体审批勘察纲要" },
          { flow_node_name: "咨询单位审批勘察纲要" },
        ],
      },

      // 我的待办配置信息
      mytaskdata: [],
      configsmytask: {
        columns: glbColumns,
        operationCol: {
          show: true,
          edit: true,
          options: {
            edit: {
              text: "处理",
            },
          },
        },
        showFilterRow: {
          show: true,
        },
        operationBtn: {
          show: true,
          add: true,
          addtext: "添加勘察纲要申请",
        },
      },

      // 运行记录配置信息
      processingdata: [],
      configsprocessing: {
        columns: glbColumns,
        operationCol: {
          show: true,
          view: true,
          options: {
            view: {
              text: "详情",
            },
          },
        },
        showFilterRow: {
          show: true,
        },
        operationBtn: {
          show: false,
        },
      },

      // 历史记录配置信息
      finisheddata: [],
      configsfinished: {
        columns: glbColumns,
        operationCol: {
          show: true,
          view: true,
          options: {
            view: {
              text: "详情",
            },
          },
        },
        showFilterRow: {
          show: true,
        },
      },
      // //公告
      // myAnnounceDlgConfig: {
      //   dialogFormVisible: false,
      //   isupdate: false,
      //   announceInfo: {
      //     remark: "",
      //     subject_id: "",
      //     url: "",
      //     notice_type: "勘察纲要",
      //     role: [],
      //     create_by: "",
      //     create_time: "",
      //     notice_content: "",
      //     notice_title: "勘察纲要审批完成",
      //     path: "",
      //     remark: ""
      //   }
      // },
      businessConfig: {
        formTitle: "北京城市副中心站<br>岩土工程勘察纲要审核意见",
      },

      // 流程配置信息
      flowConfig: {
        isfirsttime: true,
        step: 0,
      },
      //导出按钮Config
      exportTableConfig: {
        isshown: false,
        subjectId: glbSubjectId,
        model: 1,
        flowFormData: this.ruleForm,
      },

      flowComments: [],

      filetype: FILE_TYPE.outline,
      fileList: [],

      majorRight: true,

      // 业务数据与流程数据集合
      ruleForm: {
        // 基本信息
        id: 0,
        outline_id: "",
        subject_id: "",
        subject_name: "",
        tenders: "",
        major: "",
        project_id: "",
        project_name: "",

        // 计划信息
        plan: "",
        inside_work: "",
        field_work: "",
        prospecting_verification: "",
        consultation_verification: "",

        // 工作量信息
        drilling_number: 0,
        length: 0.0,
        monitor_well: 0,
        test_well: 0,

        url: "",

        firstApprover: "",
        firstContact: "",
        firstTime: "",
        firstAnswerApprover: "",
        firstAnswerTime: "",
        secondApprover: "",
        secondContact: "",
        secondTime: "",
        secondAnswerApprover: "",
        secondAnswerTime: "",
        firstMessage: "",
        firstAnswerMessage: "",
        secondMessage: "",
        secondAnswerMessage: "",
      },

      flowParam: {
        executionId: 0,
        flowNodeId: 0,
        message: "",
        procInstId: 0,
        userId: 0,
        time: "",
        contact: "",
        parent: 0,
        approver: "",
      },

      answerParent: {},

      currentRule: {},

      rules: {
        node_1: {
          project_id: [{ required: true }],
          project_name: [{ required: true }],
          plan: [{ required: true }],
          inside_work: [{ required: true }],
          field_work: [{ required: true }],
          prospecting_verification: [{ required: true }],
          consultation_verification: [{ required: true }],
          drilling_number: [{ required: true }],
          length: [{ required: true }],
          monitor_well: [{ required: true }],
          test_well: [{ required: true }],
        },
        node_2: {
          firstApprover: [{ required: true }],
          firstContact: [{ required: true }],
          firstMessage: [{ required: true }],
        },
        node_3: {
          secondApprover: [{ required: true }],
          secondContact: [{ required: true }],
          secondMessage: [{ required: true }],
        },
        node_4: {
          projectId: [{ required: true }],
          projectName: [{ required: true }],
          plan: [{ required: true }],
          inside_work: [{ required: true }],
          field_work: [{ required: true }],
          prospecting_verification: [{ required: true }],
          consultation_verification: [{ required: true }],
          drilling_number: [{ required: true }],
          length: [{ required: true }],
          monitor_well: [{ required: true }],
          test_well: [{ required: true }],
          firstAnswerApprover: [{ required: true }],
          firstAnswerMessage: [{ required: true }],
        },
        node_5: {
          projectId: [{ required: true }],
          projectName: [{ required: true }],
          plan: [{ required: true }],
          inside_work: [{ required: true }],
          field_work: [{ required: true }],
          prospecting_verification: [{ required: true }],
          consultation_verification: [{ required: true }],
          drilling_number: [{ required: true }],
          length: [{ required: true }],
          monitor_well: [{ required: true }],
          test_well: [{ required: true }],
          firstAnswerApprover: [{ required: true }],
          firstAnswerMessage: [{ required: true }],
          secondAnswerApprover: [{ required: true }],
          secondAnswerMessage: [{ required: true }],
        },
      },

      btns: {
        resolveText: "发起",
        rejectText: "重置	",
        cancelText: "取消",
      },

      // 时间选择器逻辑
      planpickerOptions: {
        disabledDate: (time) => {
          const endDateVal = this.ruleForm.field_work;
          return (
            time.getTime() < Date.now() - 8.64e7 ||
            time.getTime() > new Date(endDateVal).getTime()
          );
        },
      },
      fieldworkpickerOptions: {
        disabledDate: (time) => {
          const beginDateVal = this.ruleForm.plan;
          const endDateVal = this.ruleForm.inside_work;
          if (beginDateVal || endDateVal) {
            return (
              time.getTime() < new Date(beginDateVal).getTime() - 8.64e7 ||
              time.getTime() > new Date(endDateVal).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      insideworkpickerOptions: {
        disabledDate: (time) => {
          const beginDateVal = this.ruleForm.field_work;
          const endDateVal = this.ruleForm.prospecting_verification;
          if (beginDateVal || endDateVal) {
            return (
              time.getTime() < new Date(beginDateVal).getTime() - 8.64e7 ||
              time.getTime() > new Date(endDateVal).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      pvpickerOptions: {
        disabledDate: (time) => {
          const beginDateVal = this.ruleForm.inside_work;
          const endDateVal = this.ruleForm.consultation_verification;
          if (beginDateVal || endDateVal) {
            return (
              time.getTime() < new Date(beginDateVal).getTime() - 8.64e7 ||
              time.getTime() > new Date(endDateVal).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      cvpickerOptions: {
        disabledDate: (time) => {
          const beginDateVal = this.ruleForm.prospecting_verification;
          return (
            time.getTime() < Date.now() - 8.64e7 ||
            time.getTime() < new Date(beginDateVal).getTime() - 8.64e7
          );
        },
      },
    };
  },

  methods: {
    /**
     * @description: 初始化列表数据
     * @param {type}
     * @return:
     */
    initList() {
      // 查询待办数据
      this.$api.startitem
        .getmytasklist(listParam)
        .then((result) => {
          if (result.code == 200) {
            if (!result.data || result.data.length == 0) {
              this.mytaskdata = [];
              // this.$message.info("暂无待办任务");
              return;
            }
            this.$api.investoutline
              .getlist({ id: result.data })
              .then((result) => {
                if (result.code == 200) {
                  this.mytaskdata = result.data;
                }
              })
              .catch((err) => {
                console.log(err);
                this.$message.error(err);
              });
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });

      // 查询我已完成数据
      this.$api.startitem
        .getprocessinglist(listParam)
        .then((result) => {
          if (result.code == 200) {
            if (!result.data || result.data.length == 0) {
              this.processingdata = [];
              return;
            }
            this.$api.investoutline
              .getlist({ id: result.data })
              .then((result) => {
                if (result.code == 200) {
                  this.processingdata = result.data;
                }
              })
              .catch((err) => {
                console.log(err);
              });
          }
        })
        .catch((err) => {
          console.log(err);
        });

      // 查询整个流程已完成数据
      this.$api.startitem
        .getfinishedlist(listParam)
        .then((result) => {
          if (result.code == 200) {
            console.log("data");

            console.log(result.data);

            if (!result.data || result.data.length == 0) {
              this.finisheddata = [];
              return;
            }
            this.$api.investoutline
              .getlist({ id: result.data })
              .then((result) => {
                if (result.code == 200) {
                  this.finisheddata = result.data;
                }
              })
              .catch((err) => {
                console.log(err);
              });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    //监听上传公告结果
    operationState(msg) {
      console.log(msg);
      if (msg) {
        this.$message.success("发布成功");
      } else {
        this.$message.error("发布失败");
      }
      this.config.tableshow = !this.config.tableshow;
      this.refresh();
    },
    /* tab页面 */
    /**
     * @description: 处理流程
     * @param {type}
     * @return:
     */
    handleData(row) {
      this.$api.nodeprogress
        .query({
          subject_id: row.subject_id,
          project_id: row.project_id,
        })
        .then((res) => {
          if (res.code === 200) {
            if (res.data && res.data.length > 0) {
              this.progressInfo = {
                id: res.data[0].id,
                plan: "",
              };
            }
          }
        });
      this.initFormData_Handle(row);
    },

    /**
     * @description: 初始化流程处理相关数据
     * @param {type}
     * @return:
     */
    initFormData_Handle(row) {
      this.initBusinessFlowData();
      console.log(row);

      this.ruleForm.subject_id = row.subject_id;
      this.ruleForm.subject_name = row.subject_name;
      this.ruleForm.id = row.id;
      this.ruleForm.tenders = row.tenders;
      this.ruleForm.project_id = row.project_id;
      this.ruleForm.project_name = row.project_name;
      this.ruleForm.outline_id = row.outline_id;
      this.ruleForm.plan = row.plan;
      this.ruleForm.field_work = row.field_work;
      this.ruleForm.inside_work = row.inside_work;
      this.ruleForm.prospecting_verification = row.prospecting_verification;
      this.ruleForm.consultation_verification = row.consultation_verification;
      this.ruleForm.drilling_number = row.drilling_number;
      this.ruleForm.length = row.length;
      this.ruleForm.monitor_well = row.monitor_well;
      this.ruleForm.test_well = row.test_well;

      // ##修改##
      if (row.url != "") {
        row.url.split(";").forEach((item) => {
          if (item != "") {
            let b = item.split("/");
            this.fileList.push({
              name: b[b.length - 1].slice(18),
              realname: b.slice(b.length - 1, b.length).toString(String),
              url: item,
            });
          }
        });
      }
      // ##修改##

      let param = {
        businesstype: 1,
        businessid: row.id,
      };

      // 初始化公告默认角色列表
      this.$api.startitem.getRoleByRuningInfo(1, row.id).then((res) => {
        if (res.code === 200) {
          refRoles = res.data;
        }
      });

      this.$api.startitem
        .isfirsttime(param)
        .then((res) => {
          if (res.code === 200) {
            this.flowConfig.isfirsttime = res.data;
            this.$api.startitem
              .getworkflow({
                businessType: 1,
                businessId: row.id,
              })
              .then((res) => {
                if (res.code === 200) {
                  let { id, proc_inst_id } = res.data;
                  this.$api.startitem
                    .getcurrentstage({
                      executionId: id,
                      procInstId: proc_inst_id,
                    })
                    .then((res) => {
                      if (res.code === 200) {
                        this.config.onlyview = false;
                        this.stepconfigs.active = res.data[0];
                        this.changeStep(res.data[0]);
                        this.initComments(row.id, true, res.data[0]);

                        this.flowParam = {
                          executionId: id,
                          flowNodeId: res.data[1],
                          message: "",
                          procInstId: proc_inst_id,
                          userId: glbUser.id,
                          time: "",
                          contact: "",
                          parent: 0,
                          approver: "",
                        };
                        this.config.tableshow = false;
                      }
                    })
                    .catch((err) => {
                      console.log(err);
                    });
                }
              });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    initComments(id, todo, step) {
      this.flowComments = [];
      this.$api.startitem
        .getcomment({
          businessType: 1,
          businessId: id,
        })
        .then((res) => {
          if (res.code === 200) {
            this.flowComments = res.data;
            let firstCheck = this.flowComments.filter((item) => {
              return item.group_name === "勘察总体";
            });
            let secondCheck = this.flowComments.filter((item) => {
              return item.group_name === "咨询单位";
            });
            if (todo) {
              this.handleCommentShow(firstCheck, secondCheck);
            } else {
              this.handleCommentShowHI(firstCheck, secondCheck);
            }
          }
        });
    },

    handleCommentShow(firstCheck, secondCheck) {
      if (firstCheck.length > 0) {
        this.answerParent.first = firstCheck[firstCheck.length - 1].id;
        this.ruleForm.firstApprover =
          firstCheck[firstCheck.length - 1].approver;
        this.ruleForm.firstContact = firstCheck[firstCheck.length - 1].contact;
        this.ruleForm.firstTime = firstCheck[firstCheck.length - 1].time;
        this.ruleForm.firstMessage = firstCheck[firstCheck.length - 1].message;

        let abc = firstCheck[0];
        if (abc.children.length > 0) {
          this.ruleForm.firstAnswerMessage = abc.children[0].message;
          this.ruleForm.firstAnswerApprover = abc.children[0].approver;
          this.ruleForm.firstAnswerTime = abc.children[0].time;
        }

        if (this.flowConfig.step === 0) {
          this.currentRule = this.rules["node_4"];
        }
      }
      if (secondCheck.length > 0) {
        this.answerParent.second = secondCheck[secondCheck.length - 1].id;
        this.ruleForm.secondApprover =
          secondCheck[secondCheck.length - 1].approver;
        this.ruleForm.secondContact =
          secondCheck[secondCheck.length - 1].contact;
        this.ruleForm.secondTime = secondCheck[secondCheck.length - 1].time;
        this.ruleForm.secondMessage =
          secondCheck[secondCheck.length - 1].message;

        let bcd = secondCheck[0];
        if (bcd.children.length > 0) {
          this.ruleForm.secondAnswerMessage = bcd.children[0].message;
          this.ruleForm.secondAnswerApprover = bcd.children[0].approver;
          this.ruleForm.secondAnswerTime = bcd.children[0].time;
        }

        if (this.flowConfig.step === 0) {
          this.currentRule = this.rules["node_5"];
        }
      }
    },

    handleCommentShowHI(firstCheck, secondCheck) {
      if (firstCheck.length > 0) {
        this.ruleForm.firstApprover =
          firstCheck[firstCheck.length - 1].approver;
        this.ruleForm.firstContact = firstCheck[firstCheck.length - 1].contact;
        this.ruleForm.firstTime = firstCheck[firstCheck.length - 1].time;
        this.ruleForm.firstMessage = firstCheck[firstCheck.length - 1].message;

        let abc = firstCheck[0];
        if (abc.children.length > 0) {
          this.ruleForm.firstAnswerMessage = abc.children[0].message;
          this.ruleForm.firstAnswerApprover = abc.children[0].approver;
          this.ruleForm.firstAnswerTime = abc.children[0].time;
        }

        if (this.flowConfig.step === 0) {
          this.currentRule = this.rules["node_4"];
        }
      }
      if (secondCheck.length > 0) {
        this.ruleForm.secondApprover =
          secondCheck[secondCheck.length - 1].approver;
        this.ruleForm.secondContact =
          secondCheck[secondCheck.length - 1].contact;
        this.ruleForm.secondTime = secondCheck[secondCheck.length - 1].time;
        this.ruleForm.secondMessage =
          secondCheck[secondCheck.length - 1].message;

        let bcd = secondCheck[0];
        if (bcd.children.length > 0) {
          this.ruleForm.secondAnswerMessage = bcd.children[0].message;
          this.ruleForm.secondAnswerApprover = bcd.children[0].approver;
          this.ruleForm.secondAnswerTime = bcd.children[0].time;
        }

        if (this.flowConfig.step === 0) {
          this.currentRule = this.rules["node_5"];
        }
      }
    },

    changeStep(step) {
      this.flowConfig.step = step;
      this.currentRule = this.rules["node_" + (step + 1)];

      if (this.flowConfig.step === 0 && !this.flowConfig.isfirsttime) {
        // 重新发起
        this.btns = {
          resolveText: "重新发送",
          rejectText: "重置",
          cancelText: "取消",
        };
      } else {
        this.btns = {
          resolveText: "通过",
          rejectText: "驳回",
          cancelText: "取消",
        };
      }
    },

    /**
     * @description: 查看详情
     * @param {type}
     * @return:
     */
    viewData(row) {
      this.initFormData_View(row);
    },

    initFormData_View(row) {
      this.initBusinessFlowData();
      this.ruleForm.subject_id = row.subject_id;
      this.ruleForm.subject_name = row.subject_name;
      this.ruleForm.id = row.id;
      this.ruleForm.tenders = row.tenders;
      this.ruleForm.project_id = row.project_id;
      this.ruleForm.project_name = row.project_name;
      this.ruleForm.outline_id = row.outline_id;
      this.ruleForm.plan = row.plan;
      this.ruleForm.field_work = row.field_work;
      this.ruleForm.inside_work = row.inside_work;
      this.ruleForm.prospecting_verification = row.prospecting_verification;
      this.ruleForm.consultation_verification = row.consultation_verification;
      this.ruleForm.drilling_number = row.drilling_number;
      this.ruleForm.length = row.length;
      this.ruleForm.monitor_well = row.monitor_well;
      this.ruleForm.test_well = row.test_well;

      // ##修改##
      if (row.url != "") {
        row.url.split(";").forEach((item) => {
          if (item != "") {
            let b = item.split("/");
            this.fileList.push({
              name: b[b.length - 1].slice(18),
              realname: b.slice(b.length - 1, b.length).toString(String),
              url: item,
            });
          }
        });
      }
      // ##修改##

      let param = {
        businesstype: 1,
        businessid: row.id,
      };

      this.$api.startitem
        .isfirsttime(param)
        .then((res) => {
          if (res.code === 200) {
            this.flowConfig.isfirsttime = res.data;
            this.$api.startitem
              .getworkflow({
                businessType: 1,
                businessId: row.id,
              })
              .then((res) => {
                if (res.code === 200) {
                  let { id, proc_inst_id } = res.data;
                  this.$api.startitem
                    .getcurrentstage({
                      executionId: id,
                      procInstId: proc_inst_id,
                    })
                    .then((res) => {
                      if (res.code === 200) {
                        this.config.onlyview = true;
                        this.stepconfigs.active = res.data[0];
                        this.changeStep(res.data[0]);
                        this.initComments(row.id, false, res.data[0]);
                        this.currentRule = {};
                        this.config.tableshow = false;
                      }
                    })
                    .catch((err) => {
                      this.$message.error(err);
                    });
                }
              })
              .catch((err) => {
                this.$message.error(err);
              });
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },

    /**
     * @description: 新增前的处理
     * @param {type}
     * @return:
     */
    addNewBusiness() {
      this.initBusinessFlowData(); //初始化表单数据
      this.config.tableshow = false;
      this.config.onlyview = false;
      this.flowConfig.step = 0;
      this.flowConfig.isfirsttime = true;
      this.currentRule = this.rules.node_1;
    },

    /**
     * @description: 初始化业务表单流程 Add
     * @param {type}
     * @return:
     */
    initBusinessFlowData() {
      this.ruleForm = {
        // 基本信息
        id: 0,
        outline_id: "",
        subject_id: glbSubjectId,
        subject_name: "",
        tenders: glbUser.nick_name + "/" + glbUser.company,
        major: "",
        project_id: "",
        project_name: "",

        // 计划信息
        plan: "",
        inside_work: "",
        field_work: "",
        prospecting_verification: "",
        consultation_verification: "",

        // 工作量信息
        drilling_number: 0,
        length: 0.0,
        monitor_well: 0,
        test_well: 0,

        url: "",

        firstApprover: "",
        firstContact: "",
        firstTime: "",
        firstAnswerApprover: "",
        firstAnswerTime: "",
        secondApprover: "",
        secondContact: "",
        secondTime: "",
        secondAnswerApprover: "",
        secondAnswerTime: "",
        firstMessage: "",
        firstAnswerMessage: "",
        secondMessage: "",
        secondAnswerMessage: "",
      };
      this.fileList = [];
    },

    // 表单页面

    /**
     * @description: 正向执行流程
     * @param {type}
     * @return:
     */
    resolveFlow() {
      this.ruleForm.url = this.fileList
        .map((item) => {
          return "/" + glbSubjectId + "/勘察纲要/" + item.realname;
        })
        .join(";");


      if (!confirm(this.ruleForm.url,this.isUploadFinished)) {
        console.log("return");
        return;
      }

      this.$refs.ruleForm.validate((res) => {
        if (res) {
          this.$confirm("提交后不可更改，是否继续？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              if (this.flowConfig.isfirsttime && this.flowConfig.step === 0) {
                // 发起流程
                console.log("发起");
                this.addBusinessAndStart();
              } else if (this.flowConfig.step > 0) {
                // 审批通过
                console.log("通过");
                this.passIt();
              } else if (
                !this.flowConfig.isfirsttime &&
                this.flowConfig.step === 0
              ) {
                // 重新发起
                this.restartFlow();
              }
            })
            .catch(() => {
              return;
            });
        } else {
          this.$message.warning("请检查必填项");
        }
      });
    },

    // 发起流程具体逻辑
    addBusinessAndStart() {
      let startParam = {
        businessid: null,
        businesstype: "1",
        major: this.ruleForm.major,
        userid: glbUser.id,
        path: this.$route.path,
      };

      console.log(startParam);

      console.log(this.fileList);

      // let url = this.fileList
      //   .map(item => {
      //     return "/" + glbSubjectId + "/勘察纲要/" + item.realname;
      //   })
      //   .join(";");

      // console.log(url);

      // if (!confirm(url)) {
      //   console.log("return");
      //   return;
      // }

      let businessData = {
        id: 0,
        outline_id: "",
        subject_id: this.ruleForm.subject_id,
        subject_name: this.ruleForm.subject_name,
        tenders: this.ruleForm.tenders,
        major: this.ruleForm.major,
        project_id: this.ruleForm.project_id,
        project_name: this.ruleForm.project_name,
        plan: this.ruleForm.plan,
        inside_work: this.ruleForm.inside_work,
        field_work: this.ruleForm.field_work,
        prospecting_verification: this.ruleForm.prospecting_verification,
        consultation_verification: this.ruleForm.consultation_verification,
        drilling_number: this.ruleForm.drilling_number,
        length: this.ruleForm.length,
        monitor_well: this.ruleForm.monitor_well,
        test_well: this.ruleForm.test_well,
        url: this.ruleForm.url,
      };
      console.log("执行增加");

      this.$api.investoutline
        .add(businessData)
        .then((res) => {
          this.config.loading = false;
          if (res.code == 200) {
            this.$message.success("操作成功!");
            // 发起流程
            startParam.businessid = res.data;
            this.$api.startitem
              .starttask(startParam)
              .then((res) => {
                if (res.code === 200) {
                  this.$message.success("操作成功,已提交勘察总体审核");
                  this.refresh();
                } else {
                  this.$message.error("操作失败!" + res);
                }
              })
              .catch((err) => {
                console.log(err);
              });
          } else {
            this.$message.error("操作失败!" + res);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    /**
     * @description: 逆向拒绝流程
     * @param {type}
     * @return:
     */
    rejectFlow() {
      this.$refs.ruleForm.validate((res) => {
        if (res) {
          this.$confirm("提交后不可更改，是否继续？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              if (this.flowConfig.step === 0) {
                // 重置
                console.log("发起");

                // this.addBusinessAndStart();
              } else if (this.flowConfig.step > 0) {
                // 审批驳回
                this.rejectIt();
              }
            })
            .catch(() => {
              return;
            });
        } else {
          this.$message.warning("请检查必填项");
        }
      });
    },

    /**
     * @description: 取消，返回
     * @param {type}
     * @return:
     */
    cancelFlow() {
      this.initBusinessFlowData();
      this.config.tableshow = true;
    },

    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.tableshow = !this.tableshow;
      this.resetQueryInfo();
    },

    /**
     * @description: 重新发起流程
     * @param {type}
     * @return:
     */
    restartFlow() {
      this.config.loading = true;

      let businessData = {
        id: this.ruleForm.id,
        outline_id: this.ruleForm.outline_id,
        subject_id: this.ruleForm.subject_id,
        subject_name: this.ruleForm.subject_name,
        tenders: this.ruleForm.tenders,
        major: this.ruleForm.major,
        project_id: this.ruleForm.project_id,
        project_name: this.ruleForm.project_name,
        plan: this.ruleForm.plan,
        inside_work: this.ruleForm.inside_work,
        field_work: this.ruleForm.field_work,
        prospecting_verification: this.ruleForm.prospecting_verification,
        consultation_verification: this.ruleForm.consultation_verification,
        drilling_number: this.ruleForm.drilling_number,
        length: this.ruleForm.length,
        monitor_well: this.ruleForm.monitor_well,
        test_well: this.ruleForm.test_well,
        url: this.ruleForm.url,
      };

      // 更新勘察纲要

      this.$api.investoutline.modify(businessData).then((res) => {
        if (res.code === 200) {
          // 更新成功
          let dd = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
          let answer1 = {
            executionId: this.flowParam.executionId,
            flowNodeId: this.flowParam.flowNodeId,
            message: this.ruleForm.firstAnswerMessage,
            procInstId: this.flowParam.procInstId,
            userId: this.flowParam.userId,
            time: dd,
            contact: "",
            parent: this.answerParent.first,
            approver: this.ruleForm.firstAnswerApprover,
          };
          let answer2 = {
            executionId: this.flowParam.executionId,
            flowNodeId: this.flowParam.flowNodeId,
            message: this.ruleForm.secondAnswerMessage,
            procInstId: this.flowParam.procInstId,
            userId: this.flowParam.userId,
            time: dd,
            contact: "",
            parent: this.answerParent.second,
            approver: this.ruleForm.secondAnswerApprover,
          };
          let param = [];
          param.push(answer1);
          if (this.ruleForm.secondMessage !== "") {
            param.push(answer2);
          }

          console.log("restart param");

          console.log(param);

          this.$api.startitem
            .approve(param)
            .then((res) => {
              this.config.loading = false;
              if (res.code == 200) {
                this.$message.success("操作成功!");
                this.config.tableshow = !this.config.tableshow;
                this.refresh();
              } else {
                this.$message.error("操作失败!" + res.msg);
              }
            })
            .catch((err) => {
              this.config.loading = false;
              this.$message.error("操作失败!!" + err);
            });
        }
      });
    },

    /**
     * @description: 通过
     * @param {type}
     * @return:
     */
    passIt() {
      if (this.flowConfig.step === 1) {
        this.flowParam.message = this.ruleForm.firstMessage;
        this.flowParam.approver = this.ruleForm.firstApprover;
        this.flowParam.time = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
        this.flowParam.contact = this.ruleForm.firstContact;
        this.flowParam.parent = 0;
      } else if (this.flowConfig.step === 2) {
        this.flowParam.message = this.ruleForm.secondMessage;
        this.flowParam.approver = this.ruleForm.secondApprover;
        this.flowParam.time = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
        this.flowParam.contact = this.ruleForm.secondContact;
        this.flowParam.parent = 0;
      }

      this.config.loading = true;
      this.$api.startitem
        .approve([this.flowParam])
        .then((res) => {
          this.config.loading = false;
          if (res.code == 200) {
            this.$message.success("操作成功!");
            if (this.flowConfig.step === 2) {
              this.progressInfo.plan = formatDate(
                new Date(),
                "yyyy-MM-dd hh:mm:ss"
              );
              this.$api.nodeprogress.update(this.progressInfo).then((res) => {
                if (res.code === 200) {
                  console.log("更改实际策划时间成功");
                  this.$message.success("更改实际策划时间成功");
                }
              });
            }
            // this.config.tableshow = !this.config.tableshow;
            // this.refresh();

            if (this.flowConfig.step === 2) {
              //添加公告
              // this.myAnnounceDlgConfig.isupdate = false;
              // this.myAnnounceDlgConfig.announceInfo.create_by =
              //   "咨询总体-" + this.flowParam.approver;
              // this.myAnnounceDlgConfig.announceInfo.remark = this.ruleForm.id;
              // this.myAnnounceDlgConfig.announceInfo.subject_id = glbSubjectId;
              // this.myAnnounceDlgConfig.announceInfo.notice_content =
              //   "勘察纲要内容";
              // this.myAnnounceDlgConfig.dialogFormVisible = true;
              // this.myAnnounceDlgConfig.announceInfo.notice_title =
              //   "【" +
              //   this.ruleForm.tenders.split("/")[0] +
              //   "】勘察纲要审核完成";

              let announce = {
                subject_id: glbSubjectId,
                url: "",
                remark: this.ruleForm.id,
                notice_type: "勘察纲要",
                role: refRoles,
                create_by: this.flowParam.approver,
                create_time: this.flowParam.time,
                notice_content:
                  "【" +
                  this.ruleForm.tenders.split("/")[0] +
                  "】勘察纲要审核完成",
                notice_title:
                  "【" +
                  this.ruleForm.tenders.split("/")[0] +
                  "】勘察纲要审核完成",
                path: this.$route.path,
              };

              this.$api.announce
                .add(announce)
                .then((res) => {
                  this.config.loading = false;
                  if (res.code == 200) {
                    this.config.tableshow = !this.config.tableshow;
                    this.$message.success("操作成功!");
                    this.refresh();
                  } else {
                    this.$message.error("操作失败!" + res.msg);
                  }
                })
                .catch((err) => {
                  this.config.loading = false;
                  this.$message.error("操作失败!" + err);
                });
            } else {
              this.config.tableshow = !this.config.tableshow;
              this.refresh();
            }

            // this.config.tableshow = !this.config.tableshow;
            // this.refresh();
          } else {
            this.$message.error("操作失败!" + res.msg);
          }
        })
        .catch((err) => {
          this.config.loading = false;
          this.$message.error("操作失败!!" + err);
        });
    },

    /**
     * @description: 驳回
     * @param {type}
     * @return:
     */
    rejectIt() {
      if (this.flowConfig.step === 1) {
        this.flowParam.message = this.ruleForm.firstMessage;
        this.flowParam.approver = this.ruleForm.firstApprover;
        this.flowParam.time = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
        this.flowParam.contact = this.ruleForm.firstContact;
        this.flowParam.parent = 0;
      } else if (this.flowConfig.step === 2) {
        this.flowParam.message = this.ruleForm.secondMessage;
        this.flowParam.approver = this.ruleForm.secondApprover;
        this.flowParam.time = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
        this.flowParam.contact = this.ruleForm.secondContact;
        this.flowParam.parent = 0;
      }

      this.config.loading = true;
      this.$api.startitem
        .disapprove(this.flowParam)
        .then((res) => {
          this.config.loading = false;
          if (res.code == 200) {
            this.$message.success("操作成功!");
            this.config.tableshow = !this.config.tableshow;
            this.refresh();
          } else {
            this.$message.error("操作失败!" + res.msg);
          }
        })
        .catch((err) => {
          this.config.loading = false;
          this.$message.error("操作失败!!" + err);
        });
    },

    /**
     * @description:
     * @param {type}
     * @return:
     */
    changeProjectId(value) {
      this.projectData.forEach((item) => {
        if (item.projectId === value) {
          this.ruleForm.project_name = item.projectName;
          this.ruleForm.major = item.major;
          if (item.major === "水文") {
            this.majorRight = true;
          } else {
            this.majorRight = false;
          }
          return;
        }
      });
    },

    /**
     * @description:
     * @param {type}
     * @return:
     */
    changeProjectName(value) {
      this.projectData.forEach((item) => {
        if (item.projectName === value) {
          this.ruleForm.project_id = item.projectId;
          this.ruleForm.major = item.major;
          if (item.major === "水文") {
            this.majorRight = true;
          } else {
            this.majorRight = false;
          }
          return;
        }
      });
    },

    // 查当前流程的节点进度
    queryWorkFlowStage(row) {
      //写入项目名称
      this.project_name = row.project_name;
      if (row.major == "勘察") {
        this.majorRight = false;
      } else {
        this.majorRight = true;
      }
      // 查流程节点进度
      this.$api.startitem
        .getworkflow({
          // 勘察纲要的对应id
          businessType: "1",
          businessId: row.id,
        })
        .then((result) => {
          if (result.code == 200) {
            // 暂存此流程的流程id、节点性质

            this.executionId = result.data.id;
            this.procInstId = result.data.proc_inst_id;
            this.$api.startitem
              .getcurrentstage({
                executionId: result.data.id,
                procInstId: result.data.proc_inst_id,
              })
              .then((result) => {
                if (result.code == 200) {
                  if (result.data == null) {
                    this.stepconfigs.active = 0;
                    this.flowNodeId = 0;
                  } else {
                    this.stepconfigs.active = result.data[0];
                    this.flowNodeId = result.data[1];
                  }
                }
              })
              .catch((err) => {
                console.log(err);
                this.$message.error(err);
              });
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });

      // 查询意见comment
      this.$api.startitem
        .getcomment({
          businessType: 1,
          businessId: row.id,
          // 勘察纲要的对应typeid
        })
        .then((result) => {
          if (result.code == 200) {
            console.log(result);

            result.data.forEach((item, index) => {
              if (item.group_name === "勘察总体") {
                this.kczt_comment_his = item;
                this.iskcztfirst = false;
                this.parentkczt = item.id;
                this.reply2kczt = item.children[0].message;
              }
              if (item.group_name === "咨询单位") {
                this.zxdw_comment_his = item;
                this.iszxdwfirst = false;
                this.parentzxdw = item.id;
                this.reply2zxdw = item.children[0].message;
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });

      //  判断是不是第一次
      this.$api.startitem
        .isfirsttime({
          businessid: row.id,
          businesstype: 1,
        })
        .then((result) => {
          if (result.code == 200) {
            this.isfirsttime = result.data;
            console.log(2234);
            console.log(this.isfirsttime);
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });
    },
    resetQueryInfo() {
      this.stepconfigs.active = 0;
      this.executionId = 0;
      this.procInstId = 0;
      this.isfirsttime = true;
      this.iskcdwreply = false;
      //清空comment
      this.kczt_comment_his = {};
      this.zxdw_comment_his = {};
      this.kczt_comment_curt = "";
      this.zxdw_comment_curt = "";
    },
    // 时间选择器
    changeplanpicker(value) {
      this.ruleForm.plan = value;
    },
    changefieldworkpicker(value) {
      this.ruleForm.field_work = value;
    },
    changeinsideworkpicker(value) {
      this.ruleForm.inside_work = value;
    },
    changepvpicker(value) {
      this.ruleForm.prospecting_verification = value;
    },
    changecvpicker(value) {
      this.ruleForm.consultation_verification = value;
    },

    /** 文件附件操作区 */
    //成功回调
    handleSuccess(response, file, fileList) {},
    /**
     * @description: 超出文件数量
     * @param {type}
     * @return:
     */
    handleExceed(files, fileList) {
      this.$message.warning("最多选择 5 个文件");
    },

    /**
     * @description: 移除前
     * @param {type}
     * @return:
     */
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },

    /**
     * @description: 点击预览文件，下载
     * @param {type}
     * @return:
     */
    handlePreview(file) {
      window.open(file.url);
    },

    /**
     * @description: 处理删除
     * @param {type}
     * @return:
     */
    handleRemove(file, fileList) {
      let temp = this.fileList.filter((item) => {
        return item.uid !== file.uid;
      });
      this.fileList = temp;
      this.fileListLength -= 1;
    },

    submitUpload() {
      this.$refs.upload.submit();
    },

    /**
     * @description: 处理上传
     * @param {type}
     * @return:
     */
    beforeUpload(file) {
      let testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (this.filetype.indexOf("." + testmsg.toLowerCase()) < 0) {
        this.$message({
          message: "上传文件格式不符合要求：" + testmsg,
          type: "warning",
        });
        return false;
      }
      return true;
    },

    /**
     * @description: 上传
     * @param {type}
     * @return:
     */
    uploadSectionFile(params) {
      this.isUploadFinished = false;
      this.fileListLength += 1;

      const uid = params.file.uid;

      // ##修改##
      let URL = window.URL || window.webkitURL;
      let url = URL.createObjectURL(params.file);

      let keyname = formatDate(new Date(), "yyyyMMddhhmmss") + random();
      // ##修改##

      const fileData = new FormData();
      fileData.append("file", params.file);
      const query = {
        path: "/" + glbSubjectId + "/勘察纲要/" + keyname + params.file.name,
      };

      const config = {
        headers: {
          "Content-Type": "multipart/form-data",
          token: window.sessionStorage.getItem("token"),
        },
        // 这一段代码解决进度条不显示的问题，属于 axios 的使用知识。具体可以看文末的参考链接。
        onUploadProgress: (progressEvent) => {
          const percentCompleted = Math.floor(
            (progressEvent.loaded * 100) / progressEvent.total
          );
          params.onProgress({ percent: percentCompleted });
        },
      };

      httpfile.upload(query, config, fileData).then((res) => {
        console.log(res);
        if (res.status == 200) {
          // ##修改##
          this.fileList.push({
            url: url,
            name: params.file.name,
            realname: keyname + params.file.name,
          });

          // ##修改##
          params.onSuccess(res);

          if (this.fileListLength === this.fileList.length) {
            console.log("炒鸡成功");
            this.isUploadFinished = true;
          } else {
            console.log("普通成功");
            this.isUploadFinished = false;
          }
        }
      });
    },

    refresh() {
      if (this.$route.query.id) {
        this.$router.replace({ path: this.$route.path, query: {} });
      } else {
        this.initBusinessFlowData();
        this.config.tableshow = true;
        this.initList();
      }
    },
  },

  /**
   * @description: 生命周期钩子函数，创建组件
   * @param {type}
   * @return:
   */
  created() {
    // 全局变量
    glbUserRoleId = this.$store.state.m_user.userInfo.roleId;
    glbUserId = this.$store.state.m_user.userInfo.id;
    glbSubjectId = this.$store.state.projectInfo.projectName;
    glbUser = this.$store.state.m_user.userInfo;

    listParam = {
      projectId: glbSubjectId,
      businessType: 1,
      userId: glbUserId,
    };

    let query = this.$route.query;
    if (query.id && query.todo) {
      // 待办进入
      this.tableshow = false;
      this.$api.investoutline
        .getlist({ id: [this.$route.query.id] })
        .then((result) => {
          if (result.code == 200) {
            this.handleData(result.data[0]);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
      return;
    } else if (query.id && !query.todo) {
      // 公告进入 走view逻辑
      this.tableshow = false;
      this.$api.investoutline
        .getlist({ id: [query.remark] })
        .then((result) => {
          if (result.code == 200) {
            this.viewData(result.data[0]);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });

      return;
    }

    this.initList();
  },

  mounted() {
    if (glbUser.user_type === "1") {
      this.configsmytask.operationBtn.show = true;
      this.$api.project
        .listByCompany(glbSubjectId, glbUser.company)
        .then((res) => {
          if (res.code === 200) {
            this.projectData = res.data;
          }
        });
    } else {
      this.configsmytask.operationBtn.show = false;
    }

    //文件导出 是否可见
    this.exportTableConfig.isshown =
      this.config.onlyview && this.flowConfig.step == 3;
    this.exportTableConfig.subjectId = glbSubjectId;
  },

  /**
   * @description: 计算属性
   * @param {type}
   * @return:
   */
  computed: {
    isreplyvisable: function () {
      if (!this.isfirsttime) {
        return true;
      } else {
        return this.iskcdwreply || this.onlyview;
      }
    },
  },

  watch: {
    $route(to, from) {
      this.initList();
    },
    //文件导出 是否可见 监听变化
    "config.onlyview"(newstate, old) {
      this.exportTableConfig.isshown =
        this.config.onlyview && this.flowConfig.step == 3;
    },

    "flowConfig.step"(newstate, old) {
      if (newstate == 3) {
        this.exportTableConfig.isshown =
          this.config.onlyview && this.flowConfig.step == 3;
      }
    },
    ruleForm(newstate, old) {
      this.exportTableConfig.flowFormData = newstate;
    },
  },
};
</script>

<style lang="less" scoped>
.col-flex {
  padding-top: 30px;
  height: 100%;
  .breadcrumb-container {
    height: 30px;
    margin-top: -20px;
  }
  .maincont-container {
    height: calc(~"100% - 10px");
    margin-top: 3px;
    #tableview {
      height: 100%;
      /deep/.el-tabs {
        height: 100%;

        .el-tabs__header {
          margin: 0;
        }
        .el-tabs__content {
          height: calc(~"100% - 40px");
          .el-tab-pane {
            height: 100%;
          }
        }
      }
    }
    .flow-container {
      height: 100%;
      padding-top: 60px;
      box-sizing: border-box;
      .step {
        height: 60px;
        margin-top: -60px;
      }
      .flow-form {
        height: calc(~"100% - 10px");
        overflow: auto;

        table .form-label {
          background-color: #efefef;
          margin-bottom: 10px;
        }
        .form-title {
          margin: 10px !important;
        }

        .form-data {
          border-collapse: collapse;
          margin: auto;
          width: 85%;
          font-size: 13px;

          /deep/.el-input {
            height: normal;
            .el-input__inner {
              padding: 0px 5px !important;
            }
          }

          .el-form-item {
            padding: 0px;
            margin: 0px;
            .el-form-item__content {
              line-height: normal;
            }
            .el-select {
              display: block !important;
            }
          }
        }

        .btns {
          width: 85%;
          margin: 20px auto;
          display: flex;
          justify-content: flex-end;
        }

        .upload-demo {
          text-align: left;
        }
      }
    }
  }
  /deep/.addbutton-con {
    button {
      box-shadow: 0px 0px 0px 3px #66b1ff55;
    }
    i {
      font-size: 20px;
    }
    z-index: 100;
    position: absolute;
    top: 10px;
    right: 10px;
    margin: 5px;
    height: 40px;
    border-radius: 50%;
    // box-shadow: 0px 0px 0px 2px gray;
  }
}
</style>